//
//  XMQHttpFileUploader.m
//  testApp
//
//  Created by liaowei on 14-4-18.
//
//

#import "XMQHttpFileUploader.h"


@interface XMQHttpFileUploader ()

@end


@implementation XMQHttpFileUploader

- (id)init
{
    self = [super init];
    if (self != nil) {
        self.delegate = self;
    }
    
    return self;
}

#pragma mark -- XMQHttpFileTransferDelegate

- (void)httpFileTransfer:(NSNumber *)requestId
                 userObj:(id)userObj didFailWithError:(NSError *)error
{
    if (self.uploadDelegate != nil ||
        ![self.uploadDelegate respondsToSelector:@selector(httpUploadFailWithError:userObj:error:)]) {
        return;
    }
    
    [self.uploadDelegate httpUploadFailWithError:requestId userObj:userObj error:error];
}

- (void)httpFileTransfer:(NSNumber *)requestId userObj:(id)userObj
         didSendBodyData:(NSInteger)bytesWritten
       totalBytesWritten:(NSInteger)totalBytesWritten
totalBytesExpectedToWrite:(NSInteger)totalBytesExpectedToWrite
{
    if (self.uploadDelegate == nil ||
        ![self.uploadDelegate respondsToSelector:@selector(httpUpload:userObj:didSendBodyData:totalBytesWritten:totalBytesExpectedToWrite:)]) {
        return;
    }
    
    [self.uploadDelegate httpUpload:requestId userObj:userObj
                     didSendBodyData:bytesWritten
                   totalBytesWritten:totalBytesWritten
           totalBytesExpectedToWrite:totalBytesExpectedToWrite];
}

- (void)httpFileTransfer:(NSNumber *)requestId
                 userObj:(id)userObj didReceiveResponse:(NSURLResponse *)response
{
}

- (void)httpFileTransfer:(NSNumber *)requestId
                 userObj:(id)userObj didReceiveData:(NSData *)data
{
}

- (void)httpFileTransferDidFinishLoading:(NSNumber *)requestId userObj:(id)userObj
{
    
    if (self.uploadDelegate == nil ||
        ![self.uploadDelegate respondsToSelector:@selector(httpUploadEnd:userObj:)]) {
        return;
    }
    
    [self.uploadDelegate httpUploadEnd:requestId userObj:userObj];
}

@end
